<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>

<style>
.form-horizontal .form-group {
	margin-right: 0px;
	margin-left: 0px;
}
</style>

<form id="res-form" name="ui-adminlte-form" class="form-horizontal"
	data-toggle="validator" role="form" method="post"
	action="${pageContext.request.contextPath}/sys/resource!save.action"
	forward-action="${pageContext.request.contextPath}/sys/resource!list.action">
	<s:token></s:token>
	<input name="id" value="${entity.resourceId }" type="hidden" />

	<div class="row">
		<div class="form-group col-sm-6">
			<label>资源名称</label> <input type="text" name="entity.name"
				value="${entity.name}" class="form-control required"
				placeholder="输入资源名称" />
		</div>
		<div class="form-group col-sm-6">
			<label>序号</label> <input type="number" name="entity.orderSeq"
				value="${entity.orderSeq }" class="form-control required"
				placeholder="输入序号" />
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>父菜单 </label>
			<thx:select name="entity.parentId" type="resource"
				value="${entity.parentId }"></thx:select>
		</div>
		<div class="form-group col-sm-6">
			<label>资源编码</label> <input type="text" name="entity.code"
				value="${entity.code}" class="form-control required"
				remote="${pageContext.request.contextPath}/sys/resource!checkCode.action?id=${entity.resourceId}"
				placeholder="输入资源编码" />
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>是否菜单</label>
			<div class=" radio">
				<c:if test="${entity.resourceId != null }">
					<c:if test="${entity.menuAble=='1'}">
						<input type="radio" name="entity.menuAble" class="minimal-red"
							value="1" checked />  是
						<input type="radio" name="entity.menuAble" class="minimal-red"
							value="0" />   否
				</c:if>
					<c:if test="${entity.menuAble=='0'}">
						<input type="radio" name="entity.menuAble" class="minimal-red"
							value="1" />   是
						<input type="radio" name="entity.menuAble" class="minimal-red"
							value="0" checked />  否
				</c:if>
				</c:if>
				<c:if test="${entity.resourceId == null }">
					<input type="radio" name="entity.menuAble" class="minimal-red"
						value="1" checked />   是
					<input type="radio" name="entity.menuAble" class="minimal-red"
						value="0" />   否
			</c:if>
			</div>
		</div>
		<div class="form-group col-sm-6">
			<label>能否访问</label>
			<div class=" radio">
				<c:if test="${entity.resourceId != null }">
					<c:if test="${entity.accessible == '1'}">
						<input type="radio" name="entity.accessible" class="minimal-red"
							value="1" checked />   能
						<input type="radio" name="entity.accessible" class="minimal-red"
							value="0" />   否
				</c:if>
					<c:if test="${entity.accessible == '0'}">
						<input type="radio" name="entity.accessible" class="minimal-red"
							value="1" />   能
						<input type="radio" name="entity.accessible" class="minimal-red"
							value="0" checked />   否
				</c:if>
				</c:if>
				<c:if test="${entity.resourceId == null }">
					<input type="radio" name="entity.accessible" class="minimal-red"
						value="1" checked />   能
					<input type="radio" name="entity.accessible" class="minimal-red"
						value="0" />   否
			</c:if>
			</div>
		</div>
	</div>
	<div class="row control">
		<div class="form-group col-sm-6">
			<label>打开的位置 </label> <select name="entity.target"
				class="form-control">
				<option value="">请选择</option>
				<option value="_blank">新窗口</option>
				<option value="_parent">父框架</option>
				<option value="_top">整个窗口</option>
			</select>
		</div>
		<div class="form-group col-sm-6">
			<label>url</label> <input type="text" name="entity.url"
				value="${entity.url}" class="form-control required"
				remote="${pageContext.request.contextPath}/sys/resource!checkUrl.action?id=${entity.resourceId}"
				placeholder="输入url" />
		</div>
	</div>
	<div class="row">
		<div class="form-group  col-sm-12">
			<label>描述</label>
			<textarea class="form-control" rows="2" cols="20"
				name="entity.description">${entity.description }</textarea>
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>菜单小图标</label> <input type="text" name="entity.smallIcon"
				value="${entity.smallIcon}" class="form-control"
				placeholder="输入菜单小图标class类名" />
		</div>
		<div class="form-group col-sm-6">
			<label>资源大图标</label> <input type="text" name="entity.bigIcon"
				value="${entity.bigIcon}" class="form-control"
				placeholder="输入资源大图标" />
		</div>
	</div>
</form>

<script>
	$(function() {
		form.init();

		//父菜单 添加form-control样式
		$("select[name='entity.parentId']").attr("class", "form-control");
		//父菜单选中对象
		var option = $('select[name="entity.parentId"]').find("option:selected");
		//父菜单select绑定change事件
		$('select[name="entity.parentId"]').bind("change", function() {
			option = $(this).find("option:selected");
			if (option.val() != '') {
				$('input[name="entity.code"]').val(option.attr("class") + '_');
			} else {
				$('input[name="entity.code"]').val("");
			}
			$('input[name="entity.url"]').val("");
		});
		//资源编码 绑定keyup事件
		$('input[name="entity.code"]').bind("keyup", function() {
			var code = $(this).val();
			var url = "";
			var substr = [];
			if (code.indexOf(option.attr("class")) != -1) {
				substr = code.split("_");
				if (substr.length == 2) {
					url = substr[0] + "/" + substr[1] + "!list.action";
				} else if (substr.length == 3) {
					url = substr[0] + "/" + substr[1] + "!" + substr[2] + ".action";
				}
				$('input[name="entity.url"]').val(url);
			}
		});
		//打开的位置设置值
		$('select[name="entity.target"]').val('${entity.target}');
		
		
		icheckPlugin.init($('input[name="entity.menuAble"]'));
		
		
		var onChecked = function(event) {
			var targetVal;
			if (event) {
				targetVal = event.target.value;
			}
			if (targetVal == '0') {
				$('.control').slideUp(500);
			} else if(targetVal == '1'){
				$('.control').slideDown(500);
			}else if($('input[name="entity.accessible"]:checked').val()=='0'){
				$('.control').hide();
			}
		}

		icheckPlugin.init($('input[name="entity.accessible"]'), {
			ifChecked : onChecked
		});

		//执行初始控制事件
		 onChecked();
		
		$.extend(jQuery.validator.messages, {
			remote : "已存在"
		});
	});
</script>